{literal}
<script type="text/javascript">
	$.ui.dialog.prototype.options.bgiframe = true;
	var progbar = "<img src='{/literal}{$GLOBALS.user_site_url}/system/ext/jquery/progbar.gif{literal}' />";
	var parentReload = false;
	$(function() {
		$(".getUser").click(function(){
			$("#dialog").dialog('destroy');
			$("#dialog").attr({title: "Loading"});
			$("#dialog").html(progbar).dialog({width: 180});
			var link = $(this).attr("href");
			$.get(link, function(data){
				$("#dialog").dialog('destroy');
				$("#dialog").attr({title: "User Product Details"});
				$("#dialog").html(data).dialog({
					width: 560,
					close: function(event, ui) {
						$("#expired_date").datepicker( 'hide' );
						if (parentReload == true) {
							window.location = "?restore=1";
					}}
				});
			});
			return false;
			});

		$("#change_product_send_button").click(function(){
			val = $("#product_select").val();
			$("#product_to_change").val( val );
			var number_of_listings = $("#number_of_listings_"+val).val();
			$("#number_of_listings").val( number_of_listings );
			$("input[name='action_name']").val('change_product');
			$("#change_product_dialog").dialog('destroy').html("{/literal}[[Please wait...]]{literal}" + progbar).dialog( {width: 200});
			$("form[name='users_form']").submit();
		});
		
		$("#user_reject_send_button").click(function(){
			val = $("#rejection_reason_text").val();
			$("#rejection_reason").val(val);
			$("input[name='action_name']").val('reject');
			$("#user_reject_dialog").dialog('destroy').html("{/literal}[[Please wait...]]{literal}" + progbar).dialog( {width: 200});
			$("form[name='users_form']").submit();
		});
		
		$("tr[id^='users']").click(function(){
			var name = ($(this).attr('id'));
			if( !$(this).attr('style') ) {
				$("input[name='" + name + "']").attr('checked','checked');
				$(this).attr('style','background-color: #ffcc99');
				
			}else {
				$(this).removeAttr('style');
				$("input[name='" + name + "']").removeAttr('checked');
			}

			});
		
	});
	
	function login_as_user( name, pass ) {
		$.get('{/literal}{$GLOBALS.site_url}{literal}/login-as-user/', { username: name, password: pass}, function (data) {
			var response = $.trim(data);
			if (response == "") {
				document.login.username.value = name;
				document.login.password.value = pass;
				document.getElementById('login').submit();
			}
			else {
				popUpWindow(300,100,'Error',data);
			}
		});
	}

	function popUpWindow(widthWin, heightWin, title, message){
		$("#messageBox").dialog( 'destroy' ).html(message);
		$("#messageBox").dialog({
			width: widthWin,
			height: heightWin,
			title: title
			
		}).dialog( 'open' );
		
		return false;
	}

	function go( button ){
		if($("input:checked").length > 0 && $("#selectedAction_"+button).val() != ''){
			var action = $("#selectedAction_"+button).val();

			switch ( action ) {
			case 'send_activation_letter':
				var users = [];
				var userids = [];
				users = $("input:checked");
			
				for (var i = 0; i < users.length; i++) {
					userids[i] = users[i].name.substring(users[i].name.indexOf('[')+1,users[i].name.lastIndexOf(']'));
				}
			
				var progbar = "<img src='{/literal}{$GLOBALS.site_url}/../system/ext/jquery/progbar.gif{literal}'>";
				$(function() {
					var data = '';
					$("#dialog").dialog('destroy');
					$("#dialog").attr({title: "Loading"});
					$("#dialog").html(progbar).dialog({width: 180});
					
					$.get("{/literal}{$GLOBALS.site_url}{literal}/send-activation-letter/",{'userids[]':userids, ajax:true}, function(data){
			
						$("#dialog").dialog('destroy');
						$("#dialog").attr({title: "Sending activation emails "});
						$("#dialog").html(data).dialog({width: 300});
					});
				});
				break;
			case 'reject':
				$("#user_reject_dialog").dialog('destroy');
				$("#user_reject_dialog").dialog({title: "User Rejection", width: 350});
				break;
			case 'change_product':
				$("#change_product_dialog").dialog('destroy');
				$("#change_product_dialog").dialog({title: "Change Product", width: 350});
				break;
			case 'delete':
				if ( !confirm('Are you sure you want to delete selected user(s)?') )
					break;
			default:
				document.getElementById( 'action_name' ).value = action;
				var form = document.users_form;
				form.submit();
			}		
		} else {
			$(function() {
				$("#dialog").dialog('destroy');
				$("#dialog").attr({title: "Information"});
				$("#dialog").html("Please choose an action first").dialog({width: 300});
			});
		} 
	}

	function viewListingBlock(){
        $("#product_select option").each(function () {
        	$("#block_"+this.value).css('display', 'none');
          });
	
        $("#product_select option:selected").each(function () {
           $("#block_"+this.value).css('display', 'block');
         });
	}	
	</script>
{/literal}

{if $rangeIPs}
	<div id="bannedIPsInfo" title="Attention!" style="display:none">
		<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			The range of the IP addresses has been banned. That's why you are not able to unblock the following IP addresses:
			{foreach from=$rangeIPs item=IP}
				<b>{$IP}</b><br/>
			{/foreach}
		</p>
	</div>
	{literal}
	<script type="text/javascript"><!--
	$("#bannedIPsInfo").dialog({
		bgiframe: true,
		buttons: {
			Close: function() {
				$(this).dialog('close');
			}
		}
	});
	--></script>
	{/literal}
{/if}

{if $cantBanUsers}
	<div id="usersInfo" title="Attention!" style="display:none">
		<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			IPs of the following users were not defined, therefore they can’t be banned:<br/>
			{foreach from=$cantBanUsers item=username}
				<b>{$username}</b><br/>
			{/foreach}
		</p>
	</div>
	{literal}
	<script type="text/javascript"><!--
	$("#usersInfo").dialog({
		bgiframe: true,
		buttons: {
			Close: function() {
				$(this).dialog('close');
			}
		}
	});
	--></script>
	{/literal}
{/if}
{if $errors}
	{foreach from=$errors item="error"}
		<p class="error">[[$error]]</p>
	{/foreach}
{/if}
<div id="dialog" style="display: none"></div>
<form id="login" name="login" target="_blank"  action="{$GLOBALS.user_site_url}/login/" method="post">
    <input type="hidden" name="action" value="login" />
    <input type="hidden" name="as_user" />
    <input type="hidden" name="username" value="" />
    <input type="hidden" name="password" value="" />
</form>

<div class="clr"><br/></div>
<form method="post" name="users_form">
	 <input type="hidden" name="sorting_field" id="sorting_field" value="{$sorting_field}" />
	 <input type="hidden" name="sorting_order" id="sorting_order" value="{$sorting_order}" />
    <div class="box" id="displayResults">
        <div class="box-header">
            <div class="resultsnumber"><strong>{$usersCount}</strong> [[users]]</div>
            <div class="actionWithSelected">
                <input type="hidden" name="action_name" id="action_name" value="" />
                <input type="hidden" name="product_to_change" id="product_to_change" value="" />
                <input type="hidden" name="number_of_listings" id="number_of_listings" value="" />
                <input type="hidden" name="rejection_reason" id="rejection_reason" value="" />
                <div id="change_product_dialog" style="display: none">
                    Select Action:
                    <select name="product_select" id="product_select" style="width: 219px;"  onChange="viewListingBlock()">
                        <option value='0'>Clear Subscriptions</option>
                    {foreach from=$products item=product}
                        <option value="{$product.sid}">Add {$product.name}</option>
                    {/foreach}
                    </select>
                    <br/><br/>
					{foreach from=$products item=product}
						<div id="block_{$product.sid}" style="display: none">
							{if $product.count_listings}	
								Number of Listings: 
								<select name="number_of_listings_{$product.sid}" id="number_of_listings_{$product.sid}" style="width: 50px;">
									{foreach from=$product.count_listings item=count_listings}
										<option value="{$count_listings}">[[{$count_listings}]]</option>
									{/foreach}
								</select>
							{/if}
						</div>
					{/foreach}
                    <div class="clr"><br/></div>
                    <div class="floatRight"><input type="submit" id="change_product_send_button" name="change_product_send_button" value="Change" class="greenButton" /></div>
                </div>

                <div id="user_reject_dialog" style="display: none">
                    Enter Reject Reason:
                    <textarea name="rejection_reason_text" id="rejection_reason_text" style="width: 315px; height: 200px;"></textarea>
                    <div class="clr"><br/></div>
                    <div class="floatRight"><input type="submit" id="user_reject_send_button" name="user_reject_send_button" value="Reject" class="grayButton" /></div>
                </div>

                <div style="display:inline-block;">
                    <div class="actionSelected">
                        Actions with Selected:
                        <select id="selectedAction_up" name="selectedAction_up">
                            <option value="">Select action</option>
                            <option value="activate">Activate</option>
                            <option value="deactivate">Deactivate</option>
                            {if $ApproveByAdminChecked}
                                <option value="approve">Approve</option>
                                <option value="reject">Reject</option>
                            {/if}
                            <option value="send_activation_letter">Send Activation Email</option>
                            <option value="delete">Delete</option>
          					<option value="change_product">Change Product</option>
                            <option value="ban_ip">Ban IP</option>
                            <option value="unban_ip">Unban IP</option>
                        </select>
                        <input type="button" value="Go" class="grayButton" onclick="go('up');"/>
                    </div>
                </div>
            </div>
            <div class="pagination">
                {foreach from=$pages item=page}
                    {if $page == $currentPage}
                        <strong>{$page}</strong>
                    {else}
                        {if $page == $totalPages && $currentPage < $totalPages-3} ... {/if}
                        <a href="?page={$page}{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}&amp;users_per_page={$users_per_page}{$searchFields}">{$page}</a>
                        {if $page == 1 && $currentPage > 4} ... {/if}
                    {/if}
                {/foreach}
            </div>
            <div class="numberPerPage">
                per page:
                <select id="users_per_page" name="users_per_page" onchange="window.location = '?restore=1{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}&amp;users_per_page='+this.value;" class="perPage">
                    <option value="10" {if $users_per_page == 10}selected="selected"{/if}>10</option>
                    <option value="20" {if $users_per_page == 20}selected="selected"{/if}>20</option>
                    <option value="50" {if $users_per_page == 50}selected="selected"{/if}>50</option>
                    <option value="100" {if $users_per_page == 100}selected="selected"{/if}>100</option>
                </select>
            </div>
        </div>
        <div class="innerpadding">
            <div id="displayResultsTable">
                <table width="100%">
                    <thead>
                        <tr>
                            <th><input type="checkbox" id="all_checkboxes_control" /></th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=sid&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'sid'}DESC{else}ASC{/if}&amp;users_per_page={$users_per_page}{if $online==1}&amp;online=1{/if}">ID</a>
                            {if $sorting_field == 'sid'}{if $sorting_order == 'DESC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=username&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'username'}DESC{else}ASC{/if}&amp;users_per_page={$users_per_page}{if $online==1}&amp;online=1{/if}">Username</a>
                            {if $sorting_field == 'username'}{if $sorting_order == 'DESC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                            {if $userGroupInfo.id == 'Employer'}
                            	<th>
	                                <a href="?restore=1&amp;sorting_field=CompanyName&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'CompanyName'}DESC{else}ASC{/if}&amp;users_per_page={$users_per_page}{if $online==1}&amp;online=1{/if}">Company Name</a>
	                            {if $sorting_field == 'CompanyName'}{if $sorting_order == 'DESC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
	                            </th>
                            {elseif $userGroupInfo.id == 'JobSeeker'}
                            	<th>
	                                <a href="?restore=1&amp;sorting_field=FirstName&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'FirstName'}DESC{else}ASC{/if}&amp;users_per_page={$users_per_page}{if $online==1}&amp;online=1{/if}">First Name</a>
	                            {if $sorting_field == 'FirstName'}{if $sorting_order == 'DESC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
	                            </th>
	                            <th>
	                                <a href="?restore=1&amp;sorting_field=LastName&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'LastName'}DESC{else}ASC{/if}&amp;users_per_page={$users_per_page}{if $online==1}&amp;online=1{/if}">Last Name</a>
	                            {if $sorting_field == 'LastName'}{if $sorting_order == 'DESC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
	                            </th>
                            {/if}
                            <th>
                                <a href="?restore=1&amp;sorting_field=email&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'email'}DESC{else}ASC{/if}&amp;users_per_page={$users_per_page}{if $online==1}&amp;online=1{/if}">Email</a>
                            {if $sorting_field == 'email'}{if $sorting_order == 'DESC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                            <th>Products</th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=registration_date&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'registration_date'}DESC{else}ASC{/if}&amp;users_per_page={$users_per_page}{if $online==1}&amp;online=1{/if}">Registration Date</a>
                            {if $sorting_field == 'registration_date'}{if $sorting_order == 'DESC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=active&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'active'}DESC{else}ASC{/if}&amp;users_per_page={$users_per_page}{if $online==1}&amp;online=1{/if}">Status</a>
                            {if $sorting_field == 'active'}{if $sorting_order == 'DESC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                        	{if $ApproveByAdminChecked}
                            <th>
                                <a href="?restore=1&amp;sorting_field=approval&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'approval'}DESC{else}ASC{/if}&amp;users_per_page={$users_per_page}{if $online==1}&amp;online=1{/if}">Approval Status</a>
                                {if $sorting_field == 'approval'}{if $sorting_order == 'DESC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                        	{/if}
                            <th colspan="2" class="actions">Actions</th>
                        </tr>
                    </thead>
                    {foreach from=$found_users item=found_user name=users_block}
                        <tr class="{cycle values = 'evenrow,oddrow'}">
                            <td><input type="checkbox" name="users[{$found_user.sid}]" value="1" id="checkbox_{$smarty.foreach.users_block.iteration}" /></td>
                            <td><a href="{$GLOBALS.site_url}/edit-user/?user_sid={$found_user.sid}" title="Edit"><b>{$found_user.sid}</b></a></td>
                            <td><a href="{$GLOBALS.site_url}/edit-user/?user_sid={$found_user.sid}" title="Edit"><b>{$found_user.username}{if $found_user.parent_sid}&nbsp;<small>(sub-user)</small>{/if}</b></a></td>
                            {if $userGroupInfo.id == 'Employer'}
                            	<td>{$found_user.CompanyName}</td>
                            {elseif $userGroupInfo.id == 'JobSeeker'}
         						<td>{$found_user.FirstName}</td>
         						<td>{$found_user.LastName}</td>
                            {/if}
                            <!-- for ie -->	<td style="word-break: break-all;"><!-- for firefox--><div style="word-wrap: break-word; width: 130px;"><a href="mailto:{$found_user.email}">{$found_user.email}</a></div></td>
                            <td>{if $found_user.products > 0}<a href="{$GLOBALS.site_url}/user-product/?user_sid={$found_user.sid}" target="_blank" class="getUser">{$found_user.products}</a>{else}N/A{/if}</td>
                            <td>{$found_user.registration_date}</td>
                            <td>
                                {if $found_user.active == "1"}
                                    Active
                                    {else}
                                    Not Active
                                {/if}
                            </td>
                            {if $ApproveByAdminChecked}
                                <td>{$found_user.approval}</td>
                            {/if}
                            <td><a href="{$GLOBALS.site_url}/edit-user/?user_group={$userGroupInfo.id}&amp;user_sid={$found_user.sid}" title="Edit" class="editbutton">Edit</a></td>
                            <td><span class="greenButtonEnd"><input type="button" name="button" value="Login" class="greenButton" onclick="login_as_user('{$found_user.username}', '{$found_user.password}');" /></span></td>
                        </tr>
                    {/foreach}
                </table>
            </div>
        </div>
        <div class="box-footer">
            <div class="resultsnumber"><strong>{$usersCount}</strong> [[users]]</div>
            <div class="actionWithSelected">
                Actions with Selected:
                <select id="selectedAction_down" name="selectedAction_down" >
                    <option value="">Select action</option>
                    <option value="activate">Activate</option>
                    <option value="deactivate">Deactivate</option>
                {if $ApproveByAdminChecked}
                    <option value="approve">Approve</option>
                    <option value="reject">Reject</option>
                {/if}
                    <option value="send_activation_letter">Send Activation Email</option>
                    <option value="delete">Delete</option>
                    <option value="change_product">Change Product</option>
                    <option value="ban_ip">Ban IP</option>
                    <option value="unban_ip">Unban IP</option>
                </select>
                <input type="button" value="Go" class="greenButton" onclick="go('down');" />
            </div>
            <div class="pagination">
                {foreach from=$pages item=page}
                    {if $page == $currentPage}
                        <strong>{$page}</strong>
                    {else}
                        {if $page == $totalPages && $currentPage < $totalPages-3} ... {/if}
                        <a href="?page={$page}{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}&amp;users_per_page={$users_per_page}{$searchFields}">{$page}</a>
                        {if $page == 1 && $currentPage > 4} ... {/if}
                    {/if}
                {/foreach}
            </div>
        </div>
    </div>

</form>
    <script type="text/javascript">
        var total={if $smarty.foreach.users_block.total}{$smarty.foreach.users_block.total}{else}0{/if};
        {literal}
        function set_checkbox(param) {
            for (i = 1; i <= total; i++) {
                if (checkbox = document.getElementById('checkbox_' + i)) {
                    checkbox.checked = param;
                }
            }
        }

        $("#all_checkboxes_control").click(function() {
            if (this.checked == false){
                set_checkbox(false);
                $("tr[id^='users']").removeAttr('style');
            } else {
                set_checkbox(true);
                $("tr[id^='users']").attr( 'style','background-color: #ffcc99' );
            }
        });

    {/literal}
    </script>